//引入对象
const Koa = require('koa');
//创建服务器对象
const app = new Koa();
//配置
app.use((ctx,next)=> {
  ctx.body = 'Hello World';
  console.log(ctx.url);   //  /
  console.log(ctx.method);  //   GET
  // { host: 'localhost:8880',
  // 'cache-control': 'max-age=0',
  // 'upgrade-insecure-requests': '1',
  // 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36',
  // accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
  // 'accept-encoding': 'gzip, deflate, br',
  // 'accept-language': 'zh-CN,zh;q=0.9',
  // connection: 'close' }
  console.log(ctx.headers);
  next();

});
// Request URL: http://localhost:8880/
// Request Method: GET
// Status Code: 200 OK
// Remote Address: 127.0.0.1:1080
// Referrer Policy: no-referrer-when-downgrade
// Connection: close
// Content-Length: 18
// Content-Type: text/plain; charset=utf-8
// Date: Tue, 25 Dec 2018 05:24:55 GMT
// Proxy-Connection: keep-alive
// test: 123
app.use((ctx)=>{
   ctx.set('test','123');    //test: 123
   ctx.status=200;   //Status Code: 200 OK
   ctx.body=`<h1>大家好</h1>`  //<h1>大家好</h1>
})
app.listen(8880,(req,res)=>{
     console.log('服务器已经启动了 ')
})
